package demo2;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2021/11/17
 * Time: 10:53
 * Description:
 */
//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}
//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}

//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}

class Person {
    public void func(){

    }
}

public class TestDemo {

    public static void main(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1, "hello");
        map.put(2, "bit");
        map.put(3, "hello");
        map.put(4, "lambda");
        /*map.forEach(new BiConsumer<Integer, String>() {
            @Override
            public void accept(Integer integer, String s) {
                System.out.println("key: "+integer+" val: "+s);
            }
        });*/
        map.forEach((key,val)->System.out.println("key: "+key+" val: "+val));
    }

    public static void main10(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("ello");
        list.add("bit");
        list.add("hello");
        list.add("aambda");

     /*   list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });*/

        list.forEach(s->System.out.print(s+" "));
        //list.forEach(System.out::println);

       /* list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });*/

        list.sort((o1,o2)->o1.compareTo(o2));
        System.out.println();

        list.forEach(s->System.out.print(s+" "));

    }

    public static void main9(String[] args) {
       /* int a = 9;
        //a= 80;
        new NoParameterReturn(){
            @Override
            public int test() {
                return a;
            }
        };*/
       /* int a = 99;
        NoParameterNoReturn noParameterNoReturn = ()->{
            a = 88;//此时的a会被当中常量
            System.out.println(a);
        };*/
    }

    public static void main8(String[] args) {
        int a = 10;
        a = 99;
        new Person(){
            public void func(){
                //System.out.println(a);
            }
        }.func();

    }

    public static void main7(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1-o2;
            }
        });

        PriorityQueue<Integer> priorityQueue2 = new PriorityQueue<>((x,y)->{return x-y;});
        PriorityQueue<Integer> priorityQueue3 = new PriorityQueue<>((x,y)->x-y);

    }

    public static void main6(String[] args) {
        MoreParameterReturn moreParameterReturn = (a,x)->a+x;
        System.out.println(moreParameterReturn.test(1,2));
    }

    public static void main5(String[] args) {
        OneParameterReturn oneParameterReturn = a -> a+10;
        int ret = oneParameterReturn.test(9);
        System.out.println(ret);
    }

    public static void main4(String[] args) {
        NoParameterReturn noParameterReturn = ()->{return 10;};
        int ret = noParameterReturn.test();
        System.out.println(ret);

        NoParameterReturn noParameterReturn2 = ()->100;
        int ret2 = noParameterReturn2.test();
        System.out.println(ret2);



    }

    public static void main3(String[] args) {
        MoreParameterNoReturn moreParameterNoReturn = (a,b)->{
            System.out.println(a+b);
        };
        moreParameterNoReturn.test(10,20);

        MoreParameterNoReturn moreParameterNoReturn2 = (a,b)->
            System.out.println(a+b);

        moreParameterNoReturn2.test(10,20);
    }

    public static void main2(String[] args) {
        OneParameterNoReturn oneParameterNoReturn = (a)->{
            System.out.println("一个参数，没有返回值: "+a);
        };
        oneParameterNoReturn.test(10);

        OneParameterNoReturn oneParameterNoReturn2 = a->
                System.out.println("一个参数，没有返回值: "+a);

        oneParameterNoReturn2.test(10);

    }

    public static void main1(String[] args) {

        /*NoParameterNoReturn noParameterNoReturn = ()->{
            System.out.println("fafa");
        };
        */
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn(){
            @Override
            public void test() {
                System.out.println("void test()");
            }
        };
        noParameterNoReturn.test();

    }
}
